home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / bin / apport-unpack < prev    next >
Text File  |  2009-11-03  |  1KB  |  52 lines

  1. #!/usr/bin/python
  2.  
  3. # Extract the fields of a problem report into separate files into a new or
  4. # empty directory.
  5. #
  6. # Copyright (c) 2006 Canonical Ltd.
  7. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify it
  10. # under the terms of the GNU General Public License as published by the
  11. # Free Software Foundation; either version 2 of the License, or (at your
  12. # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
  13. # the full text of the license.
  14.  
  15. import sys, os, os.path, gettext
  16. from apport import unicode_gettext as _
  17.  
  18. import problem_report
  19.  
  20. gettext.textdomain('apport')
  21.  
  22. if len(sys.argv) != 3:
  23.     print _('Usage: %s <report> <target directory>') % sys.argv[0]
  24.     sys.exit(1)
  25.  
  26. report = sys.argv[1]
  27. dir = sys.argv[2]
  28.  
  29. # ensure that the directory does not yet exist or is empty
  30. try:
  31.     if os.path.isdir(dir):
  32.         if os.listdir(dir):
  33.             print >> sys.stderr, _('Destination directory exists and is not empty.')
  34.             sys.exit(1)
  35.     else:
  36.         os.mkdir(dir)
  37. except OSError, e:
  38.     print >> sys.stderr, e
  39.     sys.exit(1)
  40.  
  41. pr = problem_report.ProblemReport()
  42. if report == '-':
  43.     pr.load(sys.stdin)
  44. else:
  45.     try:
  46.         pr.load(open(report))
  47.     except IOError, e:
  48.         print >> sys.stderr, e
  49.         sys.exit(1)
  50. for k in pr:
  51.     open(os.path.join(dir, k), 'w').write(pr[k])
  52.